// namespace: "Forget" 
<template>
  <div class="forget-container">
    <div class="forget-form">
      <h2>忘记密码</h2>
      <el-form
        :model="forgetForm"
        ref="forget"
        :rules="forgetRules"
        label-width="80px"
        style="{color:red}"
        class="demo-ruleForm"
      >
        <el-form-item prop="email" label="邮箱">
          <el-input
            ref="input_ref"
            @keydown="keyDown"
            @keyup="keyUp"
            @blur="blurHandle"
            v-model="forgetForm.email"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="forgetForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPassword">
          <el-input type="password" v-model="forgetForm.checkPassword" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('forget')">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, getCurrentInstance } from "vue";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";

import { forgetForm, forgetRules, initForgetForm } from "../interface/forget";
export default defineComponent({
  name: "Forget",
  setup() {
    // @ts-ignore
    const { ctx } = getCurrentInstance();

    // 确定提交
    const submitForm = (formName: string) => {
      ctx.$refs[formName].validate((valid: any) => {
        if (valid) {
          // 校验无误，可进行提交操作
          forgetPassword();
          initForgetForm();
        } else {
          // 校验有误
          ElMessage.error("填写有误，请检查后重试！！");
          return false;
        }
      });
    };

    //  引入路由
    const router = useRouter();

    //忘记密码 请求接口
    const forgetPassword = () => {
      ctx
        .$axios({
          method: "get",
          url: "/serverApi/forget",
          params: {
            ...forgetForm
          }
        })
        .then((result: any) => {
          ElMessage.success("修改成功");
          setTimeout(() => {
            router.push("/login");
          }, 500);
        })
        .catch((err: Error) => {
          ElMessage.error("修改失败");
        });
    };

    const keyDown = (event: any) => {
      console.log("key down");
      if (event.key == "Enter") {
        ctx.$refs["input_ref"].blur();
        keyUp("event", "enter");
      }
    };

    const keyUp = (event: any, type: string) => {
      if (type) {
        return console.log("enter key up");
      }
      console.log("key up");
    };

    const blurHandle = () => {
      console.log("blur");
    };

    return { forgetForm, submitForm, forgetRules, keyDown, keyUp, blurHandle };
  }
});
</script>
<style lang="scss" scoped>
.forget-container {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url("../assets/image/login_bg.png");
  .forget-form {
    position: absolute;
    top: 50%;
    left: 50%;
    box-sizing: border-box;
    padding: 20px 30px 0 10px;
    width: 550px;
    height: 320px;
    // background-color: #dccced;
    border: 1px solid #dccced;
    border-radius: 12px;
    background-color: rgba(0, 0, 0, 0.1);
    transform: translate(-50%, -50%);
    h2 {
      color: #fff;
    }
    .el-button {
      margin-top: 10px;
      width: 100%;
    }
  }
}
</style>
 
 <style lang="scss"  >
.forget-form {
  .el-form-item__label {
    color: #fff !important;
  }
}
</style>